<%-- 
    Document   : chatpage
    Created on : Apr 9, 2011, 7:51:50 AM
    Author     : Setia_Negara
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.ArrayList"%>
<%@page import="database.database"%>
<%@page import="classes.User"%>
<%@page import="classes.Message"%>
<%@page import="classes.Room"%>
<%@page import="classes.Category"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="classes.User"%>
<%@page import="database.database"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="style.css" rel="stylesheet" type="text/css" />
        <script src="javascript/ajax.js" type="text/javascript"></script>
        <script src="javascript/basic.js" type="text/javascript"></script>
        <script src="javascript/chat.js" type="text/javascript"></script>
        <script src="home.js" type="text/javascript"></script>
        <script src="javascript/ajax_admin.js" type="text/javascript"></script>

        <title>chatOK</title>
    </head>
    <body>
        <div class="blanket" id="blanket">
        </div>

        <div class="Form" id="editForm">
            <label for="Edit">Edit</label>
            <input type="text" name="edit" />
            <input type="hidden" value="0" id="idcategory"/>
            <button type="button" class="tombol" value="Ok" onclick="edit()">Ok</button>
            <button type="button" class="tombol" value="Close" onclick="popup('editForm')">Close</button>
        </div>

        <div class="Form" id="addSub">
            <label for="Edit">Add Subcategory</label>
            <input type="text" name="nama" id="namaSub"/>
            <input type="hidden" value="0" id="idsubcategory" />
            <button type="button" class="tombol" value="Ok" onclick="addSub((document.getElementById('namaSub').value),(document.getElementById('idsubcategory').value));">Ok</button>
            <button type="button" class="tombol" value="Close" onclick="popup('addSub')">Close</button>
        </div>

        <div class="Form" id="addCat">
            <label for="Edit">Add Category</label>
            <input type="text" name="nama" id="namaCat"/>
            <button type="button" class="tombol" value="Ok" onclick="addCat((document.getElementById('namaCat').value),'0');">Ok</button>
            <button type="button" class="tombol" value="Close" onclick="popup('addCat')">Close</button>
        </div>

        <div class="Form" id="maxroom">
            <label for="Edit">Max Room</label>
            <input type="text" name="nama" id="value"/>
            <button type="button" class="tombol" value="Ok" onclick="maxroom((document.getElementById('value').value));">Ok</button>
            <button type="button" class="tombol" value="Close" onclick="popup('maxroom')">Close</button>
        </div>


        <div class="header">
            <div class="wrapper">
                <div class="logo">
                    <a href="chatpage.jsp"><img height="65px" alt="logo"  src="images/logo.png" /></a>
                </div>
                <div class="user">
                    Welcome, <a href="admin.jsp">Setia Negara</a> <a href="index.jsp">Logout</a>
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="main">
            <div class="wrapper">
                <div class="admincategory">
                    <div class="wrapperpanel">
                        <div class="titlepanel">
                            Edit Category
                            <%
                                        out.println("<button class=\"tombol admintombol\" id=\"" + 0 + "\" onclick=\"popup('addCat');\">");
                                        out.println("Add Category");
                                        out.println("</button>");
                            %>
                        </div>
                        <div class="adminwrapper">
                            <div class="categorylist" id="categorylist">
                                <%
                                            database db = new database();
                                            ArrayList<Category> categs = db.getCategory(0);
                                            System.out.println("query here\n");
                                            ArrayList<Category> subcategs;

                                            if (categs != null) {

                                                for (int i = 0; i < categs.size(); ++i) {
                                                    out.println("<div class=\"onecategory admin\">");
                                                    out.println(categs.get(i).name);

                                                    out.println("<button class=\"tombol admintombol\" id=\"del" + categs.get(i).id + "\" onclick=\"delCat('" + categs.get(i).id + "');\">");
                                                    out.println("Delete");
                                                    out.println("</button>");

                                                    out.println("<button class=\"tombol admintombol\" id=\"edit" + categs.get(i).id + "\" onclick=\"popup('editForm');\">");
                                                    out.println("Edit");
                                                    out.println("</button>");


                                                    out.println("<button class=\"tombol admintombol\" id=\"add" + categs.get(i).id + "\" onclick=\"popup('addSub');setvalue('idsubcategory','" + categs.get(i).id + "');\" >");
                                                    out.println("Add Subcategory");
                                                    out.println("</button>");

                                                    out.println("</div>");

                                                    subcategs = db.getCategory(categs.get(i).id);


                                                    out.println("<div class=\"sublist show padtop\" id=\"sublist" + i + "\">");
                                                    if (subcategs != null) {
                                                        for (int j = 0; j < subcategs.size(); ++j) {
                                                            //out.println("<img class=\"tree\" src=\"images/tree-nodes.png\" height=\"15px\" />");
                                                            out.println("<div class=\"onesub admin\" id=\"" + subcategs.get(j).id + "\">");
                                                            out.println(subcategs.get(j).name);

                                                            out.println("<button class=\"tombol admintombol\" id=\"del" + categs.get(i).id + "\" onclick=\"delCat('" + subcategs.get(j).id + "');\">");
                                                            out.println("Delete");
                                                            out.println("</button>");

                                                            out.println("<button class=\"tombol admintombol\" id=\"edit" + categs.get(i).id + "\" onclick=\"popup('editForm')\">");
                                                            out.println("Edit");
                                                            out.println("</button>");

                                                            out.println("</div>");
                                                        }

                                                    }
                                                    out.println("</div>");

                                                }

                                            } else {
                                                System.out.println("bye");
                                            }
                                %>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="adminuser">
                    <div class="wrapperpanel">
                        <div class="titlepanel">
                            Edit User

                            <%
                                        out.println("<button class=\"tombol admintombol\" onclick=\"popup('maxroom');\">");
                                        out.println("Max Room");
                                        out.println("</button>");
                            %>

                        </div>
                        <div class="adminwrapper">
                            <div class="userlist" id="userlist">
                                <%
                                            db.connect();
                                            ArrayList<User> arrayUser = db.getAllUser();
                                            if (!arrayUser.isEmpty()) {
                                                for (int i = 0; i < arrayUser.size(); ++i) {
                                                    out.println("<div class=\"oneuser\">");
                                                    out.println("<form action=\"\" >");
                                                    out.println(arrayUser.get(i).username);
                                                    if (arrayUser.get(i).banned) {
                                                        out.println("<input id=\"" + arrayUser.get(i).username + "#ban\" type=\"button\" class=\"tombol admintombol\" value=\"unBan\" OnClick=\"banUser('" + arrayUser.get(i).username + "#name');\"/>");
                                                    } else {
                                                        out.println("<input id=\"" + arrayUser.get(i).username + "#ban\"type=\"button\" class=\"tombol admintombol\" value=\"Ban\" OnClick=\"unBanUser('" + arrayUser.get(i).username + "#name');\"/>");
                                                    }
                                                    if (arrayUser.get(i).privilege.equals("moderator")) {
                                                        out.println("<input id=\"" + arrayUser.get(i).username + "#admin\" type=\"button\" class=\"tombol admintombol\" value=\"RemoveMomod\" OnClick=\" unMakeModerator('" + arrayUser.get(i).username + "#name');\"/>");
                                                    } else {
                                                        out.println("<input id=\"" + arrayUser.get(i).username + "#admin\" type=\"button\" class=\"tombol admintombol\" value=\"MakeMomod\" OnClick=\" makeModerator('" + arrayUser.get(i).username + "#name');\"/>");
                                                    }
                                                    out.println("</form>");
                                                    out.println("</div>");
                                                }
                                                out.println("<a href=\"redi.jsp?username=alpha&banned=ban\">TES</a>");
                                            } else {
                                                out.println("fail to load user...");
                                            }
                                %>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="footer">
            <div class="wrapper">
                Copyright &copy; 2011. ChatOK. Tugas Besar 4 Progin<br/>
                Setia Negara B. Tjaru | Ismail Sunny | Arifin Luthfi Putranto
            </div>
        </div>
    </body>
</html>
